﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using ERPStore.Extensions;

namespace ERPStore.Text
{
	public static class CSVWriter
	{
		public static object m_Lock = new object();
		public static void AppendTo<T>(T model, string fileName)
		{
			try
			{
				var line = Text.CSVSerializer<T>.Serialize(model);

				lock (m_Lock)
				{
					using (var sw = new System.IO.StreamWriter(fileName, true))
					{
						sw.WriteLine(line);
						sw.Flush();
					}
				}
			}
			catch (Exception ex)
			{
				var logger = ERPStore.GlobalConfiguration.Configuration.DependencyResolver.GetService<Logging.ILogger>();
				logger.Error(ex);
			}
		}
	}
}
